package com.zzg.demo.laboratory.jasypt;

import com.zzg.demo.util.JasyptUtil;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

@Service
public class JasyptService {
    public String testJasypt(String str, String type) {
        String format = "";
        String password = "hltn@1234";
        if(StringUtils.equals(type, "encrypt")){
            String encryptPwd = JasyptUtil.encrypt(str, password, JasyptUtil.PBE_ALGORITHMS_MD5_DES);
            format = String.format("原文:%s，加密:%s", str, encryptPwd);
        }else if(StringUtils.equals(type, "decrypt")){
            String decryptPwd = JasyptUtil.decrypt(str, password, JasyptUtil.PBE_ALGORITHMS_MD5_DES);
            format = String.format("原文:%s，解密：%s", str, decryptPwd);
        }
        System.out.println(format);
        return format;
    }
}
